import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomCommunitySearch } from '@/shared/model/room-community-search.model';
import RoomCommunitySearchService from './room-community-search.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomCommunitySearchDetails extends Vue {
  @Inject('roomCommunitySearchService') private roomCommunitySearchService: () => RoomCommunitySearchService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomCommunitySearch: IRoomCommunitySearch = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomCommunitySearchId) {
        vm.retrieveRoomCommunitySearch(to.params.roomCommunitySearchId);
      }
    });
  }

  public retrieveRoomCommunitySearch(roomCommunitySearchId) {
    this.roomCommunitySearchService()
      .find(roomCommunitySearchId)
      .then(res => {
        this.roomCommunitySearch = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
